package com.study.domain;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用的返回的类
 */
public class Message {

    //状态码：100成功，  200 失败

    private int code;
    private static final int SUCCESS=100;
    private static final int FALL=200;
    //提示信息
    private String msg;

    //用户要返回给浏览器的数据
    private Map<String,Object> extend =new HashMap<String,Object>();

    public static Message success(){
        Message result=new Message();
        result.code=SUCCESS;
        result.setMsg("处理成功！");
        return  result;
    }

    public static  Message fail(){
        Message result=new Message();
        result.code=FALL;
        result.setMsg("处理失败");
        return result;
    }

    public int getCode(){
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }

    public Message add(String key,Object value){
        this.extend.put(key, value);
        return this;
    }
}
